package lab2;

import javax.swing.*;
import javax.swing.table.TableModel;
import java.awt.*;

public class JTable_Table {
    private JTable m_table;

    public JTable_Table(String[][] matrix) {
        m_table = new JTable(matrix[0].length, matrix.length);

        TableModel model = m_table.getModel();
        for (int i = 0; i < matrix.length; ++i)
            for (int j = 0; j < matrix[i].length; ++j)
                model.setValueAt(matrix[i][j], j, i);
    }

    public Component get_table() {
        return m_table;
    }
}

class GridLayout_Table {
    private JPanel m_table = new JPanel();

    public GridLayout_Table(String[][] matrix) {
        m_table = new JPanel();
        m_table.setLayout(new GridLayout(matrix[0].length, matrix.length));
        m_table.setBackground(Color.white);

        for (int i = 0; i < matrix[i].length; ++i)
            for (int j = 0; j < matrix.length; ++j)
                m_table.add(new Label(matrix[j][i]));
    }

    public Component get_table() {
        return m_table;
    }
}

class GridBagLayout_Table {
    private JPanel m_table = new JPanel();

    public GridBagLayout_Table(String[][] matrix) {
        GridBagConstraints c = new GridBagConstraints();

        m_table.setLayout(new GridBagLayout());
        m_table.setBackground(Color.white);

        for (int i = 0; i < matrix.length; ++i)
            for (int j = 0; j < matrix[i].length; ++j) {
                c.gridx = i;
                c.gridy = j;
                m_table.add(new Label(matrix[i][j]), c);
            }
    }

    public Component get_table() {
        return m_table;
    }
}
